﻿using BusinessEntity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Nacos.AspNetCore;
using ProjectManApi.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectManApi.Controllers
{
    public class FilesController : MvcControllerBase
    {
        private readonly INacosServerManager _serverManager;
        public FilesController(INacosServerManager serverManager)
        {
            _serverManager = serverManager;

        }
        /// <summary>
        /// 保存上传文件返回的信息
        /// </summary>
        /// <param name="files">实体类</param>
        /// <returns>执行结果</returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertFiles(FilesEntity files)
        {
            try
            {
                await BusinessRule.Files.InsertFiles(files);
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        /// <summary>
        /// 根据条件查询文件
        /// </summary>
        /// <param name="Menuid">功能编号</param>
        /// <param name="Filetype">文件类型</param>
        /// <param name="Code">数据编号</param>
        /// <param name="Listid">业务数据编号</param>
        /// <returns>文件列表</returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetFile(string Menuid, string Filetype,string Code, string Listid)
        {
            try
            {
                string json = await BusinessRule.Files.GetFile(Menuid, Filetype,Code, Listid);
                return Success(json);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="FileCode"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteFile(string FileCode)
        {
            try
            {
                await BusinessRule.Files.DeleteFile(FileCode);
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
    }
}
